type point = record
  x,y:double;
end;
function Subtract(a,b:point):point; 
begin 
Result.X:=a.x-b.x; 
Result.Y:=a.y-b.y; 
end;
function LineIntersect(LineAP1,LineAP2,LineBP1,LineBP2:Point):point;
var LDetLineA, LDetLineB, LDetDivInv : double; LDiffLA, LDiffLB : Point;
begin
LDetLineA:=LineAP1.X*LineAP2.Y-LineAP1.Y*LineAP2.X;
LDetLineB:=LineBP1.X*LineBP2.Y-LineBP1.Y*LineBP2.X;
LDiffLA:=Subtract(LineAP1,LineAP2);
LDiffLB:=Subtract(LineBP1,LineBP2);
LDetDivInv:=1/((LDiffLA.X*LDiffLB.Y)-(LDiffLA.Y*LDiffLB.X));
Result.X:=((LDetLineA*LDiffLB.X)-(LDiffLA.X*LDetLineB))*LDetDivInv;
Result.Y:=((LDetLineA*LDiffLB.Y)-(LDiffLA.Y*LDetLineB))*LDetDivInv;
end;